
Partial Class Budget_ExpenditureReportBatchConfirm
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not Me.IsPostBack Then
            BindGrid()
            Me.CancelButton.Attributes.Add("onclick", "return confirm('Are you sure you want to cancel all the changes shown on this page?');")
        End If
        MessageLabel.Visible = False
    End Sub

    Private Sub BindGrid()
        Dim ctl As New FMSADataConnectorController.DataController()
        Me.BatchUploadGridView.DataSource = ctl.GetExpenditureStageTable(EntityController.AppConnectString, UserAuthorization.CurrentUser.LogonId)
        Me.BatchUploadGridView.DataBind()
        If Me.BatchUploadGridView.Rows.Count = 0 Then
            Me.BatchUploadGridView.Caption = ""
        End If
    End Sub

    Protected Sub CancelButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CancelButton.Click
        Try
            Dim ctl As New FMSADataConnectorController.DataController()
            ctl.CancelStaging(EntityController.AppConnectString, UserAuthorization.CurrentUser.LogonId)
            BindGrid()
            SetMessage("Upload has been Cancelled.", True)
        Catch ex As Exception
            SetMessage("Error Cancelling Data - " & ex.Message, False)
        End Try
    End Sub

    Protected Sub CommitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles CommitButton.Click
        Try
            Dim ctl As New FMSADataConnectorController.DataController()
            ctl.ConfirmStaging(EntityController.AppConnectString, UserAuthorization.CurrentUser.LogonId)
            SetMessage("Data has been committed to the database.", True)
            BindGrid()
        Catch ex As Exception
            SetMessage("Error Committing Data - " & ex.Message, False)
        End Try
    End Sub

    Private Sub SetMessage(ByVal msg As String, ByVal hideButtons As Boolean)
        Me.MessageLabel.Text = msg
        Me.MessageLabel.Visible = True

        If (hideButtons) Then
            Me.CancelButton.Visible = False
            Me.CommitButton.Visible = False
        Else
            Me.CommitButton.Visible = True
            Me.CancelButton.Visible = True
        End If
    End Sub

    Protected Sub UploadNewFileButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles UploadNewFileButton.Click
        Response.Redirect("ExpenditureReportBatchUpload.aspx")
    End Sub
End Class
